package com.slf.engine.threads;

import java.sql.SQLException;

import org.apache.log4j.Logger;
import org.apache.log4j.Priority;

import com.slf.engine.common.SysContext;
import com.slf.engine.http.HttpClientManager;
import com.slf.engine.services.IBusService;
import com.slf.engine.services.IFcjs0573Service;
import com.slf.engine.services.impl.BusServiceImpl;
import com.slf.engine.services.impl.Fcjs0573ServiceImpl;


public class Fcjs0573Thread extends Thread {

	private static final Logger log = Logger.getLogger(Fcjs0573Thread.class);
	private HttpClientManager manager;
	
	public Fcjs0573Thread()
	{
		super("FCJS0573_THREAD");
		init();
	}
	private void init()
	{
		IFcjs0573Service fcjs0573Service = new Fcjs0573ServiceImpl();
		manager = new HttpClientManager();
		if(fcjs0573Service.login(manager))
		{
			log.log(Priority.INFO, "开始数据抓取");
			SysContext.IS_START = true;
		}
	}
	
	public void run()
	{
		IBusService busService = new BusServiceImpl();
		while(true)
		{
			if(SysContext.IS_START)
			{
				busService.doService(manager);
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
				}
			}else{
				try {
					this.sleep(3000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
				}
			}
		}
	}
}
